package com.cango.qutz.web.auth.user.service.impl;

import com.cango.qutz.web.auth.user.service.ILoginService;
import com.cango.qutz.web.entity.MenuEntity;
import com.cango.qutz.web.entity.ResourceEntity;
import com.cango.framework.base.Constants;
import com.cango.qutz.web.auth.user.dao.IUserDao;
import com.cango.framework.base.entity.SessionUserVo;
import com.cango.qutz.web.auth.user.dao.IUserDao;
import com.cango.qutz.web.auth.user.service.ILoginService;
import com.cango.qutz.web.entity.MenuEntity;
import com.cango.qutz.web.entity.ResourceEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  登录相关业务实现类<br> 
 * 〈功能详细描述〉
 *
 * @author weih
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Service("loginService")
public class LoginServiceImpl implements ILoginService {

    @Autowired
    IUserDao userDao;
    
    @Override
    public SessionUserVo getUserByLoginName(String loginName) {
        Map<String, Object> param = new HashMap<>();
        param.put("loginId", loginName);
        return userDao.queryForObject("auth.getUserByLoginName", param);
    }

    
    @Override
    public List<MenuEntity> queryMenusByLoginUser(String loginId, String positionCode) {
        Map<String, Object> param = new HashMap<>();
        param.put("positionCode", positionCode);
        param.put("resouceType", Constants.RESOURCE_TYPE_MENU);
        return userDao.queryList("auth.getMenusByPositionCode", param);
    }


    @Override
    public List<ResourceEntity> queryButtonsByLoginUser(String loginId, String positionCode) {
        Map<String, Object> param = new HashMap<>();
        param.put("positionCode", positionCode);
        param.put("resouceType", Constants.RESOURCE_TYPE_BUTTON);
        return userDao.queryList("auth.getButtonsByPositionCode", param);
    }

    @Override
    public List<ResourceEntity> queryAdminButtons() {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("resouceType", Constants.RESOURCE_TYPE_BUTTON);
        return userDao.queryList("auth.getButtonsByAdmin", param);
    }
    @Override
    public List<MenuEntity> getAdministratorMenus() {
        return userDao.queryList("auth.getAdministratorMenus", null);
    }
    
}
